<?php
/**
 * Create by PhpStorm
 * User: lijia
 * Data: 2020/8/10
 * Time: 10:52
 */

namespace app\api\business;


use app\api\controller\UserCommon;
use app\api\model\Category;
use think\facade\Db;

class CategoryBus extends UserCommon
{
    public $model;
    public function __construct(){
        parent::__construct();
        $this->model = new Category();
    }


    public function getCategorys(){
        return $this->model->field('category_id,category_name')->select();
    }

    public function getGoods($id){
        $cate = $this->model->where('pid',$id)->field('category_id,category_name')->select()->toArray();
        foreach ($cate as $k => $v){
            $cate[$k]['goods'] = Db::name('goods')
                ->field('id,cover,title,info,price')
                ->order('id','desc')
                ->where('cid',$v['category_id'])
                ->where('status',1)
                ->select()->toArray();
        }
        return $cate;
    }

}